package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @PostMapping
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult =setmealService.pageQuerysetmeal(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @DeleteMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result deleteIds(@RequestParam List <Long> ids){
        log.info("按照Id删除当前套餐{}",ids);
        setmealService.deleteIds(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmeal(@PathVariable Long id){
        log.info("查询套餐下面的菜品{}",id);
        SetmealVO setmealVO=setmealService.getSetmeal(id);
        return Result.success(setmealVO);
    }
    @PutMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("修改信息如下{}",setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result <String> startOrstopStatus(@PathVariable("status") Integer status, Long id){
        log.info("改变当前状态{},状态是{}",id,status);
        setmealService.startOrstop(status,id);
        return Result.success();
    }
}
